use "~\reliablecontributors_FPA_data.dta", clear

*Ensure data is set as panel data*
*sort ccode year
*xtset ccode year

***********************************************************************
**Models reported in main text********
***********************************************************************


**Table 1 models, tests of H1**

*MODEL 1
nbreg absch_troops_max L.solschdum L.other_ldrtrns L.regtrans L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if troops_ever==1, cluster(ccode)

*Variable to tag observations included in the analysis*
*gen samp=0 

*replace samp=1 if e(sample)

*MODEL 2
nbreg absch_troops_max L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*MODEL 3
nbreg absch_troops_max L.solsch_3yrs L.otherldrtrns_3yrs L.regtrans_3yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)


**Marginal effects of controls discussed in the results section (from Model 3)**

*Coup risk
margins, at(L.couprisk=(0(0.005)0.025) (mean) _all (median) L.solsch_3yrs L.otherldrtrns_3yrs L.regtrans_3yrs) force   

*Total troops
margins, at(L.troops_th=(.650 7) (mean) _all (median)L.solsch_3yrs L.otherldrtrns_3yrs L.regtrans_3yrs) force
*Authorization
margins, at(authtroop_th=(41.65 98.05) (mean) _all (median)L.solsch_3yrs L.otherldrtrns_3yrs L.regtrans_3yrs) force
*Authorization change
margins, at(authtroop_change_absval_th=(3 17.484) (mean) _all (median)L.solsch_3yrs L.otherldrtrns_3yrs L.regtrans_3yrs) force


**Table 2 models, test of H2**


*MODEL 4: Interaction with 1 year
nbreg absch_troops_max L.i.solschdum##L.c.polity2_newscale L.other_ldrtrns##L.c.polity2_newscale L.regtrans L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*joint test of interaction*
testparm L.i.solschdum##L.c.polity2_newscale

*MODEL 5: Interaction with 2 years
nbreg absch_troops_max L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)


 margins, dydx(L.solsch_2yrs) at(L.polity2_newscale=(4(1)20) L.otherldrtrns_2yrs=(0) L.regtrans_2yrs=(0)) atmeans force
  
 #delimit; 
marginsplot, recast(line) recastci(rarea) scheme(s1mono) plot1opts(lcolor(gs8)) ciopt(color(black%20)) graphregion(col(white))
 xtitle("Polity Score", size(medsmall))
 ytitle("Marginal Effect of SOLS Change on Change in Troops", size(medsmall))
 title("")
xlabel(4 "-6" 5 "-5" 6 "-4" 7 "-3" 8"-2" 9 "-1" 10 "0" 11 "1" 12 "2" 13 "3" 14 "4" 15 "5" 16 "6" 17 "7" 18 "8" 19 "9" 20 "10")
yline(0, lpattern(dash))
 ;

*joint test of interaction*
testparm L.i.solsch_2yrs##L.c.polity2_newscale

*MODEL 6: Interaction with 3 years
nbreg absch_troops_max L.i.solsch_3yrs##L.c.polity2_newscale L.otherldrtrns_3yrs##L.c.polity2_newscale L.regtrans_3yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*joint test of interaction*
testparm L.i.solsch_3yrs##L.c.polity2_newscale




********************************************************************************




************************
***Appendix***
************************

******************************************************
*Descriptive statistics (Table 1A)**
******************************************************

summarize absch_troops_max L.solschdum L.solsch_2yrs L.solsch_3yrs L.other_ldrtrns L.otherldrtrns_2yrs L.otherldrtrns_3yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.regtrans L.regtrans_2yrs L.regtrans_3yrs L.milper_hth L.troops_th authtroop_th authtroop_change_absval_th L.absch_troops_max if samp==1



********************************************************************************
*Number of zeros in current DV as a result of no troops contributed (Table 2A)** 
********************************************************************************

sort ccode year

*Check number of observations that reflect a zero contribution in both t and t-1

tab dvzero_t_t1 if samp==1

*Check by dummy regime type

tab dvzero_t_t1 dem_dum if samp==1, column

**# of obs with 0 troops in t and t-1**
** democracies: 291 or 16.56% (of dem obs)
** non democracies: 256 or 25.70% (of non-dem obs)




*******************************************************************
*Average contribution by regime type across years (Figure 6A)**
*******************************************************************

collapse (mean) troops_max if troops_ever==1, by(dem_dum year)

gen dem_troops=troops_max if dem_dum==1
gen nondem_troops=troops_max if dem_dum==0

collapse dem_troops nondem_troops, by(year)

gen troops_absdiff=abs(dem_troops-nondem_troops)

line dem_troops nondem_troops troops_absdiff year, ylabel(0(250)1750) ytitle("Average Troops") xtitle("Year") legend(label(1 "Democracies") label(2 "Non democracies") label(3 "Absolute difference")) lpattern("l" "-" "_-")


******************************************************
*Total troops by regime type across years (Figure 7A)**
******************************************************

use "~\reliablecontributors_FPA_data.dta", clear
collapse (sum) troops_max if troops_ever==1, by(dem_dum year)

gen dem_troops_total=troops_max if dem_dum==1
gen nondem_troops_total=troops_max if dem_dum==0

collapse dem_troops_total nondem_troops_total, by(year)

gen troops_total_absdiff=abs(dem_troops_total-nondem_troops_total)

line dem_troops_total nondem_troops_total troops_total_absdiff year, ylabel(0(10000)70000) ytitle("Total Troops") xtitle("Year") legend(label(1 "Democracies") label(2 "Non democracies") label(3 "Absolute difference")) lpattern("l" "-" "_-")



***********************************************************
*# of contributors by regime type across years (Figure 8A)**
***********************************************************

use "~\reliablecontributors_FPA_data.dta", clear
collapse (sum) troops_any if troops_ever==1, by(dem_dum year)

gen dem_contributors=troops_any if dem_dum==1
gen nondem_contributors=troops_any if dem_dum==0

collapse dem_contributors nondem_contributors, by(year)

gen contributors_absdiff=abs(dem_contributors-nondem_contributors)

line dem_contributors nondem_contributors contributors_absdiff year, ylabel(0(10)80) ytitle("# of Contributors") xtitle("Year") legend(label(1 "Democracies") label(2 "Non democracies") label(3 "Absolute difference")) lpattern("l" "-" "_-")




*******************************************************************
***Plot contributions by Polity and regime type pre and post 1999**
*******************************************************************

use "~\reliablecontributors_FPA_data.dta", clear
scatter troops_max polity2 if troops_ever==1 & year<=1999, xlabel(-10(1)10) title(1990-1999, size(medium)) ytitle(Troops) xtitle(Polity) saving(troops_polity_pre2000)
scatter troops_max polity2 if troops_ever==1 & year>=1999, xlabel(-10(1)10) title(1999-2018, size(medium)) ytitle(Troops) xtitle(Polity) saving(troops_polity_post1999)

**Figure 9A**
graph combine troops_polity_pre2000.gph troops_polity_post1999.gph

*
twoway hist troops_max if polity2>=6 & troops_ever==1 & year<=1999, title("Democracies, 1990-1999", size(medium)) xtitle(Troops) saving(hist_demtroops_pre2000)
twoway hist troops_max if polity2<6 & troops_ever==1 & year<=1999, title("Non-democracies, 1990-1999", size(medium)) xtitle(Troops) ytitle("") saving(hist_nondemtroops_pre2000)

twoway hist troops_max if polity2>=6 & troops_ever==1 & year>=1999, title("Democracies, 1999-2000", size(medium)) xtitle(Troops) saving(hist_demtroops_post2000)
twoway hist troops_max if polity2<6 & troops_ever==1 & year>=1999, title("Non-democracies, 1999-2000", size(medium)) xtitle(Troops) ytitle("") saving(hist_nondemtroops_post2000)

**Figure 10A**
graph combine hist_demtroops_pre2000.gph hist_nondemtroops_pre2000.gph hist_demtroops_post2000.gph hist_nondemtroops_post2000.gph



***************************************************************************************
***Analysis including only states that contribute in either year t or t-1 (Table 3A)***
***************************************************************************************

*Model 7

nbreg absch_troops_max L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth  L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if dvzero_t_t1==0, cluster(ccode)

*Model 8

nbreg absch_troops_max L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth  L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if dvzero_t_t1==0, cluster(ccode)

*joint test of interaction*
testparm L.i.solsch_2yrs##L.c.polity2_newscale

 

 *************************************************************
 **Analyses of troop increases and decreases (Table 4A)*******
 *************************************************************

 **Troop increases**
*Model 9
nbreg troop_inc L.solsch_2yrs L.otherldrtrns_2yrs L.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.troop_inc authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 10
nbreg troop_inc L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.troop_inc authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

testparm L.i.solsch_2yrs##L.c.polity2_newscale


**Troop decreases**
*Model 11
nbreg troop_dec L.solsch_2yrs L.otherldrtrns_2yrs L.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.troop_dec authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 12
nbreg troop_dec L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.troop_dec authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

testparm L.i.solsch_2yrs##L.c.polity2_newscale

 
 *****************************************************************
 **Analyses accounting for multiple SOLS changes (Table 5A)*******
 *****************************************************************
 
 **Multiple SOLS changes**

*Model 13
nbreg absch_troops_max L.solsch_2yrs L.otherldrtrns_2yrs L.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1 & L.multipleSOLSch_2yrs==0, cluster(ccode)

*Model 14
nbreg absch_troops_max L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1 & L.multipleSOLSch_2yrs==0, cluster(ccode)

testparm L.i.solsch_2yrs##L.c.polity2_newscale

*Model 15
nbreg absch_troops_max L.solsch_2yrs L.otherldrtrns_2yrs L.polity2_newscale L.multipleSOLSch_2yrs  L.regtrans_2yrs  L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 16
nbreg absch_troops_max L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.multipleSOLSch_2yrs  L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_th L.absch_troops_max authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

testparm L.i.solsch_2yrs##L.c.polity2_newscale


************************************************************************
**Analysis of average troop changes over time by Polity (Figure 11A)****
************************************************************************

***For this analysis, we took the following steps: 
/*
*Using master dataset and remove all observations not in the analysis sample, leaving 2,753 observations
keep if samp==1
*Create data at Polity score level using the following command:
collapse(median) solsch_dur, by(polity2_newscale)
*To calculate the rate, we first created the variable "solsch_rate" (average number of SOLS change per year at each value of Polity) with:
gen solsch_rate=1/solsch_dur
*Take the marginal effects calculated from Model 5 and add them manually into the data as "troop_margin":
margins, dydx(L.solsch_2yrs) at(L.polity2_newscale=(4(1)20) L.otherldrtrns_2yrs=(0) L.regtrans_2yrs=(0)) atmeans force
*The annual marginal change (troop_change_rate) is calculated as:
gen troop_change_rate = solsch_rate*troop_margin
*/
***
*save "C:\Users\oestman\Dropbox\UNLV\Research\Oestman & Passmore\Journal submissions\FPA submission (2023)\Data & Analysis\Figure11A_data.dta"

*Load the separate dataset to create Figure 11A*

use "~\Figure11A_data.dta", clear
*This creates the rate graph (some manual aesthetic changes made for the manuscript)
twoway line troop_change_rate polity2_newscale if polity2_newscale>2, graphregion(col(white)) yline(0) xtitle("Polity Score", size(medsmall)) ytitle("Average annual peacekeeping change based on SOLS change frequency", size(medsmall)) title("") xlabel(4 "-6" 5 "-5" 6 "-4" 7 "-3" 8"-2" 9 "-1" 10 "0" 11 "1" 12 "2" 13 "3" 14 "4" 15 "5" 16 "6" 17 "7" 18 "8" 19 "9" 20 "10")

***********************************************************
*** Alternative specifications of DV (Table 6A)************
***********************************************************

use "~\reliablecontributors_FPA_data.dta", clear

*Model 17
nbreg absch_troops_tot L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_tot_th L.absch_troops_tot authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 18
nbreg absch_troops_tot L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_tot_th L.absch_troops_tot authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*joint test of interaction
testparm L.i.solsch_2yrs##L.c.polity2_newscale


*MODEL 19
nbreg absch_troops_mean L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_mean_th L.absch_troops_mean  authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 20
nbreg absch_troops_mean L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_mean_th L.absch_troops_mean  authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Joint test of interaction
testparm L.i.solsch_2yrs##L.c.polity2_newscale


*Model 21
nbreg absch_troops_december L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_dec_th L.absch_troops_december authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Model 22
nbreg absch_troops_december L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.milper_hth L.troops_dec_th L.absch_troops_december authtroop_th authtroop_change_absval_th yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Joint test of interaction
testparm L.i.solsch_2yrs##L.c.polity2_newscale




********************************************************************
**Check results controlling for contributor fatalities (Table 7A)***
********************************************************************

*Model 24
nbreg absch_troops_max L.solsch_2yrs L.otherldrtrns_2yrs L.regtrans_2yrs L.polity2_newscale L.gdppc_hth L.prev_conflict L.couprisk L.troops_th  L.milper_hth L.absch_troops_max authtroop_th authtroop_change_absval_th L.troop_deaths yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)


*Model 25
nbreg absch_troops_max L.i.solsch_2yrs##L.c.polity2_newscale L.otherldrtrns_2yrs##L.c.polity2_newscale L.regtrans_2yrs L.gdppc_hth L.prev_conflict L.couprisk L.troops_th  L.milper_hth L.absch_troops_max authtroop_th authtroop_change_absval_th L.troop_deaths yr_n yr_n2 yr_n3  yr_n yr_n2 yr_n3 i.ccode if samp==1, cluster(ccode)

*Joint test of interaction
testparm L.i.solsch_2yrs##L.c.polity2_newscale





